<?php

namespace app\controller\notify;

use App\controller\common\WxPayUtil;
use app\model\OrderModel;
use support\Request;
use app\service\Route;

class WxPay
{


    /**
     * description:订单支付
     * @Route(reqUrl="/notify.wxpay.orderPay")
     * author:yangkelong
     * data:2022/6/3
     */
    public function orderPay(Request $request){
        $res = WxPayUtil::notifyDecrypt($request);
        $fp=fopen('wxpay.log','a');
        fwrite($fp,"notify.wxpay.orderPay:\r\n".json_encode($res)."\r\n");
        fclose($fp);
        if($res['trade_state']=='SUCCESS'){
            $attach = json_decode($res['attach'],true);
            $orderObj = new OrderModel();
            $orderObj->where('order_id','=',$attach['order_id'])->update(['pay_type'=>1,'pay_status'=>1,'order_status'=>1,'pay_time'=>time(),'transaction_id'=>$res['transaction_id']]);
            $orderObj->payAfter($attach['order_id']);
        }
        return success();
    }

}